<template>
    <div class="tab">
        <div class="left">{{activeNum}} items left</div>
        <div class="center">
            <span 
                v-for="item in state"
                :key="item"
                :class="{current: item === filter}" 
                @click="change(item)">
                {{item}}
            </span>
        </div>
        <div class="right" @click="destory">clear completed</div>
    </div>
</template>
<script>
export default {
    props: {
        todos: {
            type: Array,
            required: true,
            status: 'all'
        },
        filter: {
            type: String,
            required: true
        }
    },
    data(){
        return{
            state: ['all', 'active', 'completed']
        }
    },
    computed: {
        'activeNum'(){
            return this.todos.filter(v=> !v.completed).length;
        }
    },
    methods: {
        change(key){
            this.$emit('toggleFilter', key)
        },
        destory(){
            this.$emit('destory')
        }
    }
}
</script>
<style lang="scss" scoped>
.tab{
    display: flex;
    align-items: center;
    background: #fff;
    height: 50px;
    text-align: center;
    .left{
        width: 20%;
    }
    .center{
        flex: 1;
        span{
            padding: 6px 10px;
            border: 1px solid transparent;
            border-radius: 5px;
            cursor: pointer;
        }
        span.current{
            border-color: rgba(255, 0, 0, .5);
        }
    }
    .right{
        width: 20%;
        cursor: pointer;
    }
    .right:hover{
        color: rgba(255, 0, 0, .5);
    }

}
</style>


